package student.action;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;


import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionContext;
import com.util.DB;
import com.util.MyLog;

import edu.student.models.Lookup;
/**
 * 
 * @author Sai Naga Sravani Peraka
 */
public class AdminLookup extends ActionSupport{

	private String table="";
	private Lookup lookup=new Lookup();
	private ArrayList<Lookup> allValues;
	public String getTable() {
		return table;
	}
	public void setTable(String table) {
		this.table = table;
	}
	public String execute() throws Exception {

		Map session = ActionContext.getContext().getSession();
		String table = ServletActionContext.getRequest().getParameter("table");
		MyLog.log("param:"+table);
		session = ActionContext.getContext().getSession();
		MyLog.log("session"+session.get("table"));
		if(table.equals(null)){
			this.table = (String)session.get("table");
     		MyLog.log("lookup value:"+table);
		}
     	if (session.get("table") == null) {
	      	session.put("table",table );
	      	MyLog.log("session"+session.get("table"));
	    }

     	this.allValues=lookup.find(table,"");
     	for (int i = 0; i < allValues.size(); i++){
        	Lookup test = allValues.get(i);
        	MyLog.log("name:"+test.getName());
        	MyLog.log("iscurrent:"+test.getIs_current());
        	MyLog.log("table:"+test.getTable());
        	System.out.println("table:"+test.getTable());
        	System.out.println("subject_code"+test.getSubject_code());
        	System.out.println("iscurrent:"+test.getIs_current());
        }
/*     	if(table.equals("course")){
     		this.allValues=lookup.findCourse(table,"");
     	}*/
		return "success";
				
	}
	public Lookup getLookup() {
		return lookup;
	}
	public void setLookup(Lookup lookup) {
		this.lookup = lookup;
	}
	public ArrayList<Lookup> getAllValues() {
		return allValues;
	}
	public void setAllValues(ArrayList<Lookup> allValues) {
		this.allValues = allValues;
	}
	
}
